package com.banmao.mall.controller.client;

import com.banmao.mall.mapper.OrderMapper;
import com.banmao.mall.model.bo.client.order.OrderSubmitBO;
import com.banmao.mall.model.pojo.*;
import com.banmao.mall.model.vo.BaseRespVO;
import com.banmao.mall.model.vo.admin.market.FileUploadVO;
import com.banmao.mall.model.vo.client.order.detail.OrderDetailsVO;
import com.banmao.mall.model.vo.client.order.footprint.FootPrintVO;
import com.banmao.mall.model.vo.client.order.nopayment.NoPaymentVO;
import com.banmao.mall.service.admin.MarketService;
import com.banmao.mall.service.client.GoodsService;
import com.banmao.mall.service.client.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/wx")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    MarketService marketService;
    @RequestMapping("/order/list")
    public BaseRespVO wxOrderList(Integer showType,Integer page,Integer size){
    //showType=1&page=1&size=10
        //showType 1 未付款 也就是查找order_status = 101
        NoPaymentVO paymentVO = orderService.selectNoPaymentList(showType,page,size);
        return BaseRespVO.ok(paymentVO);

    }
    @RequestMapping("order/detail")
    public BaseRespVO wxOrderDetail(Integer orderId){
        OrderDetailsVO orderDetailsVO = orderService.selectOrderDetails(orderId);
        return BaseRespVO.ok(orderDetailsVO);
    }

    @RequestMapping("order/prepay")
    public BaseRespVO wxOrderPrepay(@RequestBody OrderGoods orderGoods){
        Integer orderId = orderGoods.getOrderId();
        orderService.updateOrderPrepay(orderId);
        return BaseRespVO.ok("订单支付成功");
    }

    @RequestMapping("order/cancel")
    public BaseRespVO wxOrderCancel(@RequestBody OrderGoods orderGoods){
        Integer orderId = orderGoods.getOrderId();
        orderService.cancelOrderPrepay(orderId);
        return BaseRespVO.ok(null);
    }

    @RequestMapping("/storage/upload")
    public BaseRespVO storageCreate(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request) {

        FileUploadVO fileUploadVO = marketService.fileUpload(multipartFile, request);
        if (fileUploadVO == null) {
            return BaseRespVO.error("上传失败啦", 401);
        }

        return BaseRespVO.ok(fileUploadVO);
    }
    @RequestMapping("order/comment")
    public BaseRespVO wxOrderComment(@RequestBody Comment comment){
        orderService.insertOrderComment(comment);
        return BaseRespVO.ok(null);
    }
    @RequestMapping("order/goods")
    public BaseRespVO wxOrderGoods(Integer orderId,Integer goodsId){
        Goods goods = orderService.selectOrderGoods(orderId,goodsId);
        return BaseRespVO.ok(goods);
    }

    @RequestMapping("order/confirm")
    public BaseRespVO wxOrderConfirm(@RequestBody OrderGoods orderGoods){
        Integer orderId = orderGoods.getOrderId();
        orderService.updateOrderConfirm(orderId);
        return BaseRespVO.ok(null);

    }
    @RequestMapping("order/delete")
    public BaseRespVO wxOrderDelete(@RequestBody OrderGoods orderGoods){
        Integer orderId = orderGoods.getOrderId();
        orderService.updateOrderDeleted(orderId);
        return BaseRespVO.ok(null);
    }

    @RequestMapping("order/refund")
    public BaseRespVO wxOrderRefund(@RequestBody OrderGoods orderGoods){
        Integer orderId = orderGoods.getOrderId();
        orderService.updateOrderRefund(orderId);
        return BaseRespVO.ok(null);
    }
    @RequestMapping("footprint/list")
    public BaseRespVO wxFootprintList(Integer page,Integer size){
        FootPrintVO footPrintVO = orderService.selectFootprintList(page,size);
        return BaseRespVO.ok(footPrintVO);
    }

    @RequestMapping("feedback/submit")
    public BaseRespVO wxFeedbackSumbit(@RequestBody Feedback feedback){
        orderService.insertFeedbackSumbit(feedback);
        return BaseRespVO.ok(null);
    }

    @RequestMapping("order/submit")
    public BaseRespVO wxOrderSubmit(@RequestBody OrderSubmitBO orderSubmitBO){
        Integer integer = orderService.insertOrderSubmit(orderSubmitBO);
        OrderGoods orderGoods = new OrderGoods();
        orderGoods.setOrderId(integer);
        return BaseRespVO.ok(orderGoods);
    }

}
